package 多线程;

public class threadLocalTest {
    // 方法：get set remove 
    static ThreadLocal<String> threadLocal = new ThreadLocal<>();
    public static void main(String[] args) {
        new Thread(() -> {
            String name = Thread.currentThread().getName();
            threadLocal.set("thread-001");
            print(name);
            System.out.println(name + "removed:" + threadLocal.get());
        }).start();
        new Thread(() -> {
            String name = Thread.currentThread().getName();
            threadLocal.set("thread-002");
            print(name);
            System.out.println(name + "removed:" + threadLocal.get());
        }).start();
    }
    static void print(String str){
        System.out.println(str + ":" + threadLocal.get());
        threadLocal.remove();
    }
}
